#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Va,USA
    Posts
    2
    Rep Power
    0
    I have following code. Its ok if i have only one City name and prov. name. Now i have changed that user can put in multiple City and state names. so every time txtMktCityName and txtMktPhyStateProv are changing to txtMktCityName0 and xtMktPhyStateProv0 and so on depending on the user how many values are being entered. so i was wondering how to write Java script so that code also changes dynamically as txt names are changed.

    <SCRIPT Language="JavaScript">
    function checkCityName(mthis)
    { if(mthis.txtMktCityName.value=="")
    {
    alert("Please Enter the Marketing City Name");
    return false;
    }
    if(mthis.txtCountryCode.value=="1")
    {
    if(mthis.txtMktPhyStateProv.value=="")
    {
    alert("Please Enter the Mkt State Prov Name");
    return false;
    }
    }
    return true;
    }
    </SCRIPT>

    Thanks
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    23
    Rep Power
    0

    Question


    I really don't know what you're meaning, but if it is to dynamically refer to formfields this is a way to do it:

    <html>
    <script>

    function yeah( iElement ) {

    alert("Value=" + document.frmYeah.elements["txtYeah" + iElement].value);
    document.frmYeah.btn.focus();
    }
    </script>

    <body bgcolor="#ffffff" text="#000000" id=all>

    <form name="frmYeah">
    <input onBlur="yeah(1)" name="txtYeah1"><br>
    <input onBlur="yeah(2)" name="txtYeah2"><br>
    <input type="submit" name="btn">
    </form>

    </body>
    </html>


    Here you can see that I use the 'elements' array with a composit string to refer to the element name ("txtYeah" + "1" e.g.)

Similar Threads

  1. Replies: 0
    Last Post: January 6th, 2004, 03:05 PM
  2. External JavaScript file problem
    By FTK2003 in forum JavaScript Development
    Replies: 11
    Last Post: September 13th, 2003, 12:21 PM
  3. External JavaScript file from within a JavaScript function?
    By DKDiveDude in forum JavaScript Development
    Replies: 10
    Last Post: August 19th, 2003, 04:24 AM
  4. delimiting javascript
    By scream in forum JavaScript Development
    Replies: 3
    Last Post: August 15th, 2003, 05:03 PM
  5. getting javascript error when using PHP and javascript
    By Dalamar in forum JavaScript Development
    Replies: 8
    Last Post: December 17th, 2001, 08:41 AM

IMN logo majestic logo threadwatch logo seochat tools logo