Me again with the Javascript question

Javascript coding ..

Moderators: macek, egami, gesf

amycrystal123
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Oct 26, 2004 9:45 am

Me again with the Javascript question

Postby amycrystal123 » Wed Oct 27, 2004 11:05 am

Hi there,
You would have seen my previous post .
Here, I have another question. I have a select box. Depending upon the value of the select box, I want either a text box or another select box to be viewed (but on the same row of the table, one instead of another).

Is there a way? I was thinking of the visible property.. but I do not want to use it as it defeats my purpose in putting 2 kinds of form elements (text or select) on the same place on the same row based on the value of the third select box element.

Here, I do not want the page to reload. This way, I retain the values of the form. Any ideas, please?

Thanks.
Amy.

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Wed Oct 27, 2004 2:07 pm

if you want it without a page reload the visible property is your only option. But do note that you will have to load all possible outcomes for each selection of the first select box and so on. This meaning your page size may be large.

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

Postby ruturajv » Wed Oct 27, 2004 7:33 pm

in the case that you have you need to post/get parameters to the page and then print the form accordingly

eg..

Code: Select all

if ($_POST['form'] == 1)  {
  echo $form1;
} else {
  echo $form2;
}

amycrystal123
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Oct 26, 2004 9:45 am

Hi there!

Postby amycrystal123 » Thu Oct 28, 2004 7:06 am

Thanks for your suggestions.

How do we know which form element has been visible when the page is submitted to another page. Depending on what value I select in the select box, either a text box or another select box becomes visible. So, I can consider only one of those values in the next page. Validations also follow.
Please suggest.

Ruturajv - could you ellaborate on your idea? Here, again, we submit the form right. It is not dynamic.

Thank you.
Amy.

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Re: Hi there!

Postby swirlee » Thu Oct 28, 2004 7:50 am

amycrystal123 wrote:How do we know which form element has been visible when the page is submitted to another page. Depending on what value I select in the select box, either a text box or another select box becomes visible. So, I can consider only one of those values in the next page. Validations also follow.


Use the value of the select box (the same one which determines which element is showe) to determine, er, which element was shown.

amycrystal123
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Oct 26, 2004 9:45 am

Hi Guys! Found my Answer!

Postby amycrystal123 » Mon Nov 01, 2004 12:33 pm

Hi guys,
I found a way to my solution. I thought to let you know about it also. I have solved the problem by use of DHTML. I have <div id="myid">assigned to the cell where I would like to have the select box or the text box based on the onChange event of another select box.

On the onChange event of the other select box, I call a Javascript function, which based on the value of that selected item, sets the inner HTML value of the div id to either text box or select box. Please see the code below:
**********************************************************
<html>
<head>
<script language="Javascript">
function onCheck()
{
var choice = document.newForm.inputFieldType.options.selectedIndex;
if (choice == 0)
document.getElementById('myid').innerHTML = "<input type='text' name='myText' value='Type TextValue' onFocus=\"this.select()\">";
else
document.getElementById('myid').innerHTML = "<select name='mySelectBox'><option value=1>Choice1</option><option value=2>Choice2</option><option value=3>Choice3</option></select>";
}
</script>
<title>test Form</title>
</head>

<body>

<h2>Please input the following values..</h2>
<form name = "newForm" action="TestFormInput.php" method="post">
<table>
<tr>
<td>Select Type Of Form Element:</td>
<td>
<select name="inputFieldType" onChange="return onCheck();">
<option value="Text Box" >Text Box</option>
<option value="Select Box" >Select Box</option>
</select>
</td>
</tr>

<tr>
<td>Selected Item:</td>
<td><div id="myid">
<?php
if (isset($_POST[myText]))
print "<input type='text' name='myText' value=Text box selected' onFocus=\"this.select()\">";
else if (isset($_POST[mySelectBox]))
print "<select name='mySelectBox'><option value=1>choice1</option><option value=2>choice2</option><option value=3>choice3</option></select>";
else
print print "<select name='mySelectBox'><option value=1>choice1</option><option value=2>choice2</option><option value=3>choice3</option></select>";

?>
</div></td>
</tr>

<tr><td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td></tr>
</table>
</form>
</body>
</html>
**********************************************************

Thanks for all your help !


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest

cron