By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,908 Members | 2,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,908 IT Pros & Developers. It's quick & easy.

How to insert a value into value="" attribute fro a javascript?

P: 1
Dear All,

I'm new to this!

I wanna insert selected values from form "SaveModel" to form "SaveMake" [HTML]<input name="makeID" value="<<<<need to insert here(x)>>>>">[/HTML]
[HTML]<input name="make" value="<<<<need to insert here(optvalue)>>>>">[/HTML]

when i try it works only for the selected value and in an instance it clears the <input...>.

Please help me on this.

This is my Java Script.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function alertMake(){
  3.     var x = document.getElementById("selectMake").selectedIndex;
  4.     var optvalue = document.getElementsByTagName("option")[x].text;
  5.     var ex = "This will update all the Models under Make " + optvalue;
  6.     var r=confirm(ex)
  7.   if (r==true)
  8.     {
  9.     document.getElementById('min').innerHTML= SaveMake.makeID.value = x;
  10.     document.getElementById('mine').innerHTML= SaveMake.make.value = optvalue;
  12.     }
  13.   else
  14.     {
  15.     optvalue = "";
  16.     x = "";
  17.     document.getElementById('min').innerHTML= SaveMake.makeID.value = x;
  18.     document.getElementById('mine').innerHTML= SaveMake.make.value = optvalue;
  20.     }
  22. }
  23. </script>
This is a part of my SaveMMY.php

[PHP]<form action="SaveMMY.php" name="SaveMake" method="post">
Make ID: <input id="min" name="makeID" type="text" value="" size="5" readonly="true">
Make:<input type="text" id="mine" name="make" value="<?php if(isset($EditMake)) echo ($make) ;?>">
<input type="submit" name="SaveMake" value="Save">

<form action="SaveMMY.php" name="SaveModel" method="post">
Make: <select name="selectMake">
<option value="0">Select Make</option>
<?php echo ($allMakesHtml); ?>
<input type="submit" name="EditMake" value="Edit Make" onClick="alertMake()" >
Oct 6 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
Welcome to TSDN!

Change line 9 in your JavaScript to:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('min').value = x;
and similarly for line 10, 17 and 18. You've accessed the element. It has a value attribute. Use it instead of innerHTML.

Please use code tags when posting code:

Your JavaScript code goes here...
Oct 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.