Page 1 of 2
expand <input type..
Posted: Fri Jun 18, 2004 2:58 am
by ol4pr0
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
Posted: Fri Jun 18, 2004 3:15 am
by feyd
hmm.. I think .innerHTML may be best in this situation. Say you have the following code
example onlyCode: 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>
Posted: Fri Jun 18, 2004 3:23 am
by ol4pr0
Thanks i will google some more on that innerHTML
Posted: Fri Jun 18, 2004 3:29 am
by feyd
updated code
fixed a slight tag problem.. it works now.. Javascript 1.2 required though.. I think.. maybe 1.1
Posted: Fri Jun 18, 2004 5:32 am
by ol4pr0
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..
Posted: Fri Jun 18, 2004 12:52 pm
by ol4pr0
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...
Posted: Fri Jun 18, 2004 1:00 pm
by feyd
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.
Posted: Fri Jun 18, 2004 3:54 pm
by ol4pr0
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 ..
Posted: Fri Jun 18, 2004 3:58 pm
by feyd
did you change the method of the form to "post"?
Posted: Fri Jun 18, 2004 4:05 pm
by ol4pr0
nope i did not.. i only tried the echo with $_POST - GET - REQUEST
stupid of me that that will make the differance, very dumb ...
Posted: Fri Jun 18, 2004 4:18 pm
by feyd
...using $submit, would suggest register_globals is on.. is this true?
Posted: Fri Jun 18, 2004 4:44 pm
by ol4pr0
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
Posted: Fri Jun 18, 2004 4:48 pm
by feyd
uhm... name="gname" maybe..

Posted: Fri Jun 18, 2004 5:49 pm
by ol4pr0
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.
Posted: Fri Jun 18, 2004 6:04 pm
by feyd
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...