Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    struggling once more

    i have a small piece of javascript i have written using a prompt, i need to take what is entered into the prompt box and use it in an if statement, can anyone help me?

    <html>

    <head>

    <SCRIPT LANGUAGE = JavaScript>
    function CityTimes() {
    prompt("Please Input Your City Below","Type Here") ;



    </SCRIPT>

    <meta http-equiv="Content-Language" content="en-gb">
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>City Times</title>
    </head>

    <body>

    <p><u><font size="7"><b>City Times</b></font></u></p>
    <p>New York</p>
    <p>Paris</p>
    <p>Moscow</p>
    <p>Beijing</p>
    <p>Tokyo</p>
    <p>Sydney</p>

    <input type = "button" value="Click here to input a city" name="cmdTimes" onclick ="CityTimes() " >

    </body>

    </html>

    anyone?

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is an example of a prompt return value used in an if.

    Code:
    <html>
      <head>
        <title>City Times</title>
        <script type="text/javascript">
          function CityTimes() {
            var s = prompt("Please Input Your City Below","Paris") ;
    
            var paras = document.getElementsByTagName("p");
            for (var i = 0; i < paras.length; i++) {
              if (paras[i].innerHTML == s) {
                paras[i].style.backgroundColor = "yellow";
              } else {
                paras[i].style.backgroundColor = "";
              }
            }
          }
        </script>
      </head>
      <body>
        <p><u><font size="7"><b>City Times</b></font></u></p>
        <p>New York</p>
        <p>Paris</p>
        <p>Moscow</p>
        <p>Beijing</p>
        <p>Tokyo</p>
        <p>Sydney</p>
        <input type="button" value="Click here to input a city" name="cmdTimes" onclick="CityTimes();" />
      </body>
    </html>
    david_kw


  •  

    Posting Permissions

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