Solved

update inputbox with select box values using php and html  code

Posted on 2011-03-01
6
542 Views
Last Modified: 2012-05-11
i have a slect box and after it has changed it would copy the vlaue in one input box into another.
as well as hit the button and it will copy the value of the selct box into the other input box.
i have provided the code below just cannot seem to get them to operate off the select box
any help would be appreciated thanks
<input class="textinput" maxlength="255" name="caschild2editAinp" id="caschild2editAinp_id" size="40" />
	<input class="textinput" value="test data" maxlength="255" name="caschild2editBinp" id="caschild2editBinp_id" size="40" />
	
	<select class="select" style="width: 250px" name="caschild2editA" id="caschild2editA_id"
			onchange=alert("fff")
			this.form.caschild2editAinp.value = this.form.caschild2editBinp.value;
			><option value='10875' >Accounting-Business Management</option><option value='10877' >State Arts Associations</option></select>
	
	<td><br></br>
	<input class="textinput" maxlength="255" name="testloadfromselect" id="testloadfromselect_id" size="40" />
	<input type=button value='Use Value >>'
		onclick='this.form.caschild2editAinp.value = this.form.caschild2editA.value;'>
	</td>			    		

Open in new window

0
Comment
Question by:sydneyguy
6 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 200 total points
ID: 35006968
put this in head section of your page :

function doTheCopy(obj) {
   alert("fff");
   document.getElementById("caschild2editAinp_id").value = document.getElementById("caschild2editBinp_id").value;
}

Open in new window


0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 100 total points
ID: 35006980
replace line 5-6 by

onchange="document.getElementById('caschild2editAinp_id').value = document.getElementById('caschild2editBinp_id').value";
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35007039
>put this in head section of your page :

inside script tag of course :)

<script language="javascript">
function doTheCopy(obj) {
   alert("fff");
   document.getElementById("caschild2editAinp_id").value = document.getElementById("caschild2editBinp_id").value;
}
</script>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Assisted Solution

by:Vimal DM
Vimal DM earned 200 total points
ID: 35009192
Hai,

Find below code, just copy and execute those lines

<script language="javascript" type="text/javascript">
      function setSelectedVal(){
        var selObj = document.getElementById("caschild2editA");
        var val = selObj.options[selObj.selectedIndex].value;
        document.getElementById("caschild2editBinp").value = val;       
      }
      
      function setUseVal(){       
        document.getElementById("testloadfromselect").value = document.getElementById("caschild2editBinp").value;       
      }
</script>
<input class="textinput" maxlength="255" name="caschild2editAinp" id="caschild2editAinp_id" size="40" />
      <input class="textinput" value="test data" maxlength="255" name="caschild2editBinp" id="caschild2editBinp_id" size="40" />      
      <select class="select" style="width: 250px" name="caschild2editA" id="caschild2editA" onchange="setSelectedVal()">
      <option value='10875' >Accounting-Business Management</option><option value='10877' >State Arts Associations</option></select>
      <td><br></br>
      <input class="textinput" maxlength="255" name="testloadfromselect" id="testloadfromselect_id" size="40" />
      <input type=button value='Use Value >>'
            onclick="setUseVal()">
      </td>            
0
 

Author Comment

by:sydneyguy
ID: 35013646
i can get the code going while its static on the page and have the code below where the first section works and displays the info on the select box, section 2 displays the second data but does not work, where this select has been dynamicaly built via ajax to work with the above cascade.
function showSelected()
{
//  section 1
      alert("in");
      var selObj = document.getElementById('casparent1edit_id');
      var selIndex = selObj.selectedIndex;
      alert(selIndex)
      alert(selObj.options[selIndex].value);
      alert(selObj.options[selIndex].text);
// section 2      
var selObj = document.getElementById('caschild1edit_id');
      var selIndex = selObj.selectedIndex;
      alert(selIndex)
      alert(selObj.options[selIndex].value);
      alert(selObj.options[selIndex].text);
}
      
0
 

Author Closing Comment

by:sydneyguy
ID: 35013972
ok its going well thanks for every ones input, bit of every ones input to get me going, put the system back to getther and cleaned up my page and the code and that now works well , did my call from the onchange and the dynamic now works spot on so thanks for all your help

function settypeC(){
      var selObj = document.getElementById('caschild2editC');
      var selIndex = selObj.selectedIndex;
      document.getElementById('caschild2editCval').value = selObj.options[selIndex].text;
}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question