Click to See Complete Forum and Search --> : PHP and Javascript related


jbachris
04-27-2006, 07:24 PM
I think this can be done with javascript.

I have a job listings manager I've built. When a person logs in to edit one of the job postings I need some help. Right now I've got the following code to edit the type of job:

<tr>
<td align="left"><b><font face="Tahoma, Verdana, Arial, Helvetica, sans-serif" color="#000000" size="1">Type: </font></b></td>
<td align="left"><input size="50" maxlength="150" type="text" name="type" value="<?php echo $row->type; ?>"></td></tr>


What I would like to do is put a <select> box in the row below this, where the user can select the "type" from the drop-down list and when they select one, it automatically updates the <input name="type"> box.

Thanks for any help!

zeb
04-27-2006, 07:53 PM
Try this:

<input size="50" maxlength="150" type="text" name="type" value="<?php echo $row->type; ?>"><br>
<br>
<select name='filler2' onchange="document.formName.elements['type'].value = this.options[this.selectedIndex].value;">
<option value='1'>job type 1</option>
<option value='2'>job type 2</option>
</select>

Naito
04-27-2006, 08:01 PM
Another option/example would be.

<html>
<head>
<title>Test</title>
</head>
<body>

<script type="text/javascript">
function changename(select) {
document.form1.name1.value = select;
}
</script>

<form name="form1" method="POST" enctype=application/x-www-form-urlencoded>
Enter Name Here: &nbsp;
<input name="name1" type="INT" size="30" value=""><br>
<select size="1" name="cname" onChange="changename(this.value)">
<option value="">Please Select A Value</option>
<option value="John">John</option>
<option value="Amy">Amy</option>
</select>


</body>
</html>

Naito
04-27-2006, 08:07 PM
Also note that if you would rather forget the function part of the script you could do onChange="document.form1.name1.value = this.value" Instead of the current onChange and throw out the whole <script></script> lines. It just seems a bit more tidy when it's part of a function.