tags:

views:

26

answers:

2

i have following code

<html>

<script type="text/javascript">
function writeit()
{
    var tbox = document.getElementById('a_tbox_1');
    if (tbox)
    {
        tbox.value = '';
    }
    tbox = document.getElementById('a_tbox_2');
    if (tbox)
    {
        tbox.value = '';
    }
}
</script>

<form name="a_form">
Product name:
  <input type="text" id="a_tbox_1" name="a_tbox" value="" />

  price : <input type="text" id="a_tbox_2" name="a_tbox" value="" />
<input type="button" name="btn" value="write it" onclick="writeit()" />
</form>

</html>

main idea of program is that i should give me possibilites to write two value product name and price and click after write ii it should write these informations in some text how to do it?please help

A: 
function writeit()
{
    var strValue = '';
    var tbox = document.getElementById('a_tbox_1');
    if (tbox)
    {
        //tbox.value = '';
        // add:
        strValue = 'name: ' + tbox.value;
    }
    if(strValue != '')
        strValue += ', ';
    tbox = document.getElementById('a_tbox_2');
    if (tbox)
    {
        //tbox.value = '';
        // add:
        strValue += 'price: ' + tbox.value + ' € :)';
    }
    alert(strValue);
    // or do whatever you want with it...
}
Martin
A: 

Your questin is not clear, but try the code below and see if its what you are looking for:

<html>
  <head>
  <title></title>
<script type="text/javascript">
function writeit() {
    var tbox = document.getElementById('a_tbox_1'), tbox2 = document.getElementById('a_tbox_2');
    if (tbox.value && tbox2.value){
         alert('product = ' + tbox.value + " :: price = " + tbox2.value);

         // sendData('action.php?product=' + tbox.value + '&price=' + tbox2.value); (you can send your data via ajax)

        tbox.value = ''; 
        tbox2.value = '';
        return false;
    }
}  
</script>
  </head>
  <body>
  <form name="a_form">
      Product name: <input type="text" id="a_tbox_1" name="a_tbox" value="" />
      Price : <input type="text" id="a_tbox_2" name="a_tbox" value="" />
      <input type="button" name="btn" value="write it" onclick="writeit()" />
  </form>
  </body>
</html>
Q_the_dreadlocked_ninja