Current location: Hot Scripts Forums » General Web Coding » JavaScript » new to javascript and running into a problem

new to javascript and running into a problem

Reply
  #1 (permalink)  
Old
New Member
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
new to javascript and running into a problem

Hello everyone, I'm new to javascript and Hot Scripts so please excuse me if doing something dumb here. I've built a form on my website to update entries on my database. It runs a loop to create the form for each row in the database. I'm then trying to use javascript to modify one of the fields when you've made a change to the field. Right now I've got it where the javascript is recognizing a change to each of the fields but its only performing the task on the last field. Can someone point me in the right direction to fix this problem?

The field that I'm trying to change is the "imbalance" field. I'm trying to get it to multiply the entry
by 1,000. For example I would like the user to type in "35" and when they tab out of the field the value will be "35,000".

Here is my form code: this will produce a form with 7 rows from the database to be updated
<?php
$sql = "SELECT * FROM mocs ORDER BY id";

$result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
$numrows= mysql_num_rows($result);
echo $numrows;
$i = 0;
echo '<table width="50%">';
echo '<tr>';
echo '<td>ID</td>';
echo '<td>Symbol</td>';
echo '<td>Buy/Sell</td>';
echo '<td>Imbalance</td>';
echo '<td>Price</td>';
echo '</tr>';
echo "<form id='formUpdate' name='formUpdate' method='post' action='update.php'>\n";
while ($moc = mysql_fetch_array($result)) {
echo '<tr>';
echo "<td>{$moc['id']}<input type='hidden' name='id[$i]' value='{$moc['id']}' /></td>";
echo "<td><input id='symbol' type='text' size='5' name='symbol[$i]' value='{$moc['symbol']}' /></td>";
echo "<td><input id='buySell' type='text' size='5' name='buySell[$i]' value='{$moc['buySell']}' /></td>";
echo "<td><input id='imbalance[$i]' type='text' size='10' name='imbalance[$i]' value='{$moc['imbalance']}' /></td>";
echo "<td><input id='price' type='text' size='10' name='price[$i]' value='{$moc['price']}' /></td>";
echo '</tr>';
++$i;
}


echo '<tr>';
echo "<td><input type='submit' value='submit' /></td>";
echo '</tr>';
echo "</form>";
echo '</table>';

my javascript code is:

for (i=0; i<7; i++){
var imb="imbalance[" + i + "]";


var addK = document.getElementById(imb);
console.log(addK);

addK.onchange=function(){
if (addK.value !== ""){
addK.value=addK.value*10;
}
};
};
Reply With Quote

Featured Marketplace Scripts (view more)

Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript not running in all browsers xavier039 JavaScript 6 03-17-10 03:24 PM
Running Javascript code returned form an AJAX call End User JavaScript 6 09-14-09 03:34 PM
Unknown Javascript/Ajax problem vitron JavaScript 9 06-05-09 12:44 PM
Help with javascript print code? pcinfoman JavaScript 25 06-01-07 06:36 PM
Running javascript before sending php mail phpdoctor PHP 3 04-04-07 04:47 PM


All times are GMT -5. The time now is 11:06 AM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.