JavaScript and client side scripting.
Moderator: General Moderators
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jun 18, 2004 2:58 am
Oke, i have no idea on how or what just think that with php i will not get the resutl.
lets say i wanna make a search but in differant sections, which all have differant search values ofcourse..
so first i want to determen which section, according to that section have a couple of more input fields ( or option ) with the other search options.
example.
Code: Select all
<option>php</option>
<option>java</option>
<option>c++</option>
and the submit button lol.
Oke.. now if the user selects php i wanna expand this search form.
with some other fields but on the same page. Same for all the other options.
Now how do i do this! ( i dont have a clue what i am looking for so googling .. )
any ideas
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 18, 2004 3:15 am
hmm.. I think .innerHTML may be best in this situation. Say you have the following code
example only Code: Select all
<html>
<script language="Javascript">
function getElem(id)
{
return document.getElementById?document.getElementById(id):document.allїid];
}
function updateForm(index)
{
var updArea = getElem('updArea');
switch(index)
{
case 1: // php
updArea.innerHTML = 'php selected';
break;
default:
updArea.innerHTML = 'please select an item in the drop down';
break;
}
}
</script>
<body>
<form action="foo.php" method="get">
<select onchange="updateForm(this.selectedIndex)">
<option>------</option>
<option>php</option>
<!-- whatever else... -->
</select><span id="updArea">please select an item in the drop down</span></form>
</body>
</html>
Last edited by
feyd on Fri Jun 18, 2004 3:28 am, edited 1 time in total.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jun 18, 2004 3:23 am
Thanks i will google some more on that innerHTML
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 18, 2004 3:29 am
updated code
fixed a slight tag problem.. it works now.. Javascript 1.2 required though.. I think.. maybe 1.1
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jun 18, 2004 5:32 am
Thanks i will try agian, i got it working however when putting the code in the page it stop working
some error with the 7 caracter of updArea.innerHTML
now i figured out the java part needs to go in the head, but.. still nothing..
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jun 18, 2004 12:52 pm
Oke .. youre last one seem to work better, ofcourse with some changes
i am wondering how do i get the $vars
tried $_GET / $_POST / $_REQUEST...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 18, 2004 1:00 pm
my example is set up to use get, however, the select does not have a name, so it may have a random-ish name association if you are looking for that. You may want to name the select.
It may help to post the code you are using now.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jun 18, 2004 3:54 pm
oke, i am not behind my own computer now.
but what i basicly did, is changed the
Code: Select all
case 1:
updArea='<input type=text name=text></input>'
than later on. the foo.php
Code: Select all
<?php
if (isset($submit)) {
echo $_POST['text'] ;
}
?>
error returned undefined index text ..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 18, 2004 3:58 pm
did you change the method of the form to "post"?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jun 18, 2004 4:05 pm
nope i did not.. i only tried the echo with $_POST - GET - REQUEST
stupid of me that that will make the differance, very dumb ...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 18, 2004 4:18 pm
...using $submit, would suggest register_globals is on.. is this true?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jun 18, 2004 4:44 pm
yes, i have them on..
dont know why cuase i am using $_GET and $_SERVER['PHP_SELF'] all over the site, so if i am correct it should work with globals off aswell correct ?
here is the code as i have it now, * am on a 56k here so connecting and disconnecting otherwise my phonebill will kill me.
Code: Select all
<script language="Javascript">
function getElem(id)
{
return document.getElementById?document.getElementById(id):document.allїid];
}
function updateForm(index)
{
var updArea = getElem('updArea');
switch(index)
{
case 1:
updArea.innerHTML = '<br>Game Name:<input type="text" name"gname" size="10"></input>';
break;
case 2:
updArea.innerHTML = '<br>Game Name:<input type="text" name"gname" size="10"></input>';
break;
case 3:
updArea.innerHTML = '<br>Game Name:<input type="text" name"gname" size="10"></input>';
break;
case 4:
updArea.innerHTML = '<br>Game Name:<input type="text" name"gname" size="10"></input>';
break;
default:
updArea.innerHTML = 'Please Select';
break;
}
}
</script>
<form action="foo.php" method="post">
<select onchange="updateForm(this.selectedIndex)">
<option>-select-</option>
<option>ps2</option>
<option>xbox</option>
<option>pc</option>
<!-- whatever else... -->
</select><span id="updArea"></span><br>
<INPUT TYPE="submit" name="submit" value="submit"></form>
Code: Select all
<?
# this on the foo.php nothing great just testing it..
echo $_POST['gname'];
?>
produced error
Undefined index: gname in foo.php on line 2
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 18, 2004 4:48 pm
uhm... name="gname" maybe..
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jun 18, 2004 5:49 pm
Didnt i put that in the input type ? or am i blind.... ( could be. ) lol
Am tryng to get the values form the input type ofcourse i will need the one from the select box aswell.
a input submit button in the cases did not work.. i tried that.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jun 18, 2004 6:04 pm
making a local version of yours, after making the names have assignment (=) in them, and doing print_r($_POST) in foo.php, it works perfectly..
I would suggest not checking for $submit or $_POST['submit'] as neither may be present if someone used the enter key to submit the form...