470,596 Members | 1,443 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

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

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
1 5903
16,027 Expert Mod 8TB
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.

Similar topics

1 post views Thread by Demoso | last post: by
5 posts views Thread by johnsuth | last post: by
4 posts views Thread by hao | last post: by
20 posts views Thread by Mark Harrison | last post: by
1 post views Thread by =?Utf-8?B?ZGF2aWQ=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.