Results 1 to 5 of 5

Thread: Javascript help

  1. #1

    Exclamation Javascript help

    Heres my problem: I have the following code which works off a form. I want when you hit 'Submit' for it to reload the current page (.html) and display the price which is determined by the code.

    <script language="JavaScript"><!--
    function sum(objRef) {
    var result = 0;
    result += (objRef.motherboard.value - 0);
    result += (objRef.processor.value - 0);
    result += (objRef.memory.value - 0);
    result += (objRef.harddrive.value - 0);
    document.write
    (result)
    }
    //--></script>

    Currently, when i click submit the document.write throws the result to a new page, which is not what i want.

    Also, is there a way to make it so if the user doesn't make a choice (ie: leaves the default), to give an error message?

  2. #2
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    Put a span somewhere in the page wherever you want the result to be:

    <span id="priceResult"></span>

    Then change:

    document.write(result);

    To:

    document.getElementById('priceResult').innerText = result;
    nu-metal.org :: coming soon

  3. #3
    This works excellent, thanks so much.

    Only problem is that it doesnt work in Mozilla. Any suggestions to get it to work in Mozilla/Firefox/Netscape ?

  4. #4
    Join Date
    Jan 2003
    Location
    Perth, WA, Australia
    Posts
    1,276
    Change "innerText" to "innerHTML"

    Didn't realise innerText didn't work in them, sorry.
    nu-metal.org :: coming soon

  5. #5
    Originally posted by digitok
    Change "innerText" to "innerHTML"

    Didn't realise innerText didn't work in them, sorry.
    No biggie, i actually figured it out myself the Text --> HTML thing, via google

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •