newbie - simple passing of parameter to function problem

Discussion in 'Javascript' started by Steve, Feb 7, 2006.

  1. Steve

    Steve Guest

    I have the following function in my .net page

    <script language=javascript>
    function selectFile(fileUrl)
    {
    if(navigator.appName.indexOf('Microsoft')!=-1)
    window.returnValue=fileUrl;
    else
    window.opener.setAssetValue(fileUrl);
    self.close();
    }
    </script>

    and the following code in the page

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    <input id="Button1" type="button" value="button"
    onclick="selectFile('textbox1value')"/>

    I want the user entry in TextBox1 to be sent as the parameter of the
    selectFile function for the onclick event of the button.

    i.e. for the user to enter something into TextBox1, and then to click
    on the button. The text he enters into TextBox1 will be used for the
    Parameter of the selectFile function.
    Steve, Feb 7, 2006
    #1
    1. Advertising

  2. Steve

    VK Guest

    Steve wrote:
    > I have the following function in my .net page
    >
    > <script language=javascript>
    > function selectFile(fileUrl)
    > {
    > if(navigator.appName.indexOf('Microsoft')!=-1)
    > window.returnValue=fileUrl;
    > else
    > window.opener.setAssetValue(fileUrl);
    > self.close();
    > }
    > </script>
    >
    > and the following code in the page
    >
    > <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    >
    > <input id="Button1" type="button" value="button"
    > onclick="selectFile('textbox1value')"/>
    >
    > I want the user entry in TextBox1 to be sent as the parameter of the
    > selectFile function for the onclick event of the button.
    >
    > i.e. for the user to enter something into TextBox1, and then to click
    > on the button. The text he enters into TextBox1 will be used for the
    > Parameter of the selectFile function.


    ....
    ....onclick="selectFile(this.form.TextBox1.value)"...
    ....
    VK, Feb 7, 2006
    #2
    1. Advertising

  3. VK wrote:

    > Steve wrote:
    >> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


    Server-side code is of little value when discussing client-side scripting.

    >> <input id="Button1" type="button" value="button"

    ^^^^^^^^^^^^[1] ^^^^^^^^^^^^^^[2]

    [1] Your button probably does not need an ID.
    [2] The button's caption should be meaningful.

    >> onclick="selectFile('textbox1value')"/>

    ^^^^^^^[1] ^[2]

    [1] The button will not work without client-side script support,
    so you should generate it with client-side script.
    [2] IE does not support XHTML (yet).

    >> I want the user entry in TextBox1 to be sent as the parameter of the
    >> selectFile function for the onclick event of the button.
    >>
    >> i.e. for the user to enter something into TextBox1, and then to click
    >> on the button. The text he enters into TextBox1 will be used for the
    >> Parameter of the selectFile function.

    >
    > ...
    > ...onclick="selectFile(this.form.TextBox1.value)"...
    > ...


    ... onclick="selectFile(this.form.elements['TextBox1'].value)" ...


    PointedEars
    Thomas 'PointedEars' Lahn, Feb 7, 2006
    #3
  4. Steve

    Randy Webb Guest

    Thomas 'PointedEars' Lahn said the following on 2/7/2006 5:17 PM:

    >> ...
    >> ...onclick="selectFile(this.form.TextBox1.value)"...
    >> ...

    >
    > ... onclick="selectFile(this.form.elements['TextBox1'].value)" ...


    Either is acceptable and proper.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Feb 7, 2006
    #4
  5. Steve

    Steve Guest

    Thank you everyone for your replies.

    I have tried both methods but with either one keep getting the error:

    is null or not an object this.form.TextBox1.value

    or

    is null or not an object this.form.elements['TextBox1'].value
    Steve, Feb 7, 2006
    #5
  6. Steve

    Steve Guest

    ok when I remove the .net tags it works perfectly

    i.e. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> doesn't
    work

    but

    <input id="TextBox1" type="text" /> works

    I wonder if there is a way of making the .net tag textbox work. That
    would be much more useful.
    Steve, Feb 7, 2006
    #6
  7. Steve wrote:

    > ok when I remove the .net tags it works perfectly
    >
    > i.e. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> doesn't
    > work
    >
    > but
    >
    > <input id="TextBox1" type="text" /> works


    As I said, you should omit the `/' and should not serve XHTML to IE.

    > I wonder if there is a way of making the .net tag textbox work. That
    > would be much more useful.


    I wonder what the ".net tags" generate. For _that_ is what can be accessed
    with client-side scripting.


    PointedEars
    Thomas 'PointedEars' Lahn, Feb 8, 2006
    #7
  8. Steve

    Steve Guest

    Thanks for this pointedears
    Steve, Feb 8, 2006
    #8
  9. Steve wrote:

    > Thanks for this pointedears


    You are welcome. What are you referring to?

    <URL:http://www.safalra.com/special/googlegroupsreply/>
    <URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>


    PointedEars
    Thomas 'PointedEars' Lahn, Feb 8, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Newsgroup - Ann
    Replies:
    5
    Views:
    599
    John Carson
    Jul 30, 2003
  2. mosscliffe
    Replies:
    6
    Views:
    313
  3. Mister B
    Replies:
    8
    Views:
    541
    Nick Keighley
    Aug 26, 2010
  4. Yang

    Simple Parameter Passing Problem

    Yang, Apr 16, 2007, in forum: Javascript
    Replies:
    3
    Views:
    94
  5. AzamSharp
    Replies:
    2
    Views:
    174
Loading...

Share This Page