SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2001
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help in javascript

    At very First I want to say that I am new for Javascript and I need help. I have a variable say p1
    now I want that the value of form action="" will varry according to the variable p1.
    e.g

    if (p1==1)
    then <form name="form1" method="post" action="1.php">
    etc

    Thank you
    http://www.classicsoftwares.com - Classic Web Development
    http://www.classicresellers.com - Web Hosting for Resellers
    http://www.classicwebhosting.com - Web Hosting Solutions
    http://www.classichostingtool.com - Web Based Tool for Windows

  2. #2
    SitePoint Evangelist
    Join Date
    Jan 2002
    Posts
    420
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How many

    How many options will p1 equal? Just one or a whole bunch like 1-10?
    Wavelan

  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi miithilesh,

    <form .....>
    ....elements, at least one of which changes or determines p1...
    <input type='button' value='submit' onClick="sendIt(this.form)">
    </form>

    function sendIt(formObj)
    {
    var ok2Send = true;
    ...code to validate or whatever
    ... if(somefield validation fails) ok2Send = false;
    if (ok2Send)
    {
    switch (p1)
    {
    case 1: // means p1 == 1
    formObj.action = 'somepage.asp'
    break;
    case 2: // means p1 == 2
    formObj.action = 'somepage2.asp'
    break;
    ...etc...
    }
    formObj.submit();
    }
    }

    above will work if p1 is a global var, else you need to pass p1 to the function. If you have only 2 actions use an if/else instead of the switch

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

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