Results 1 to 6 of 6

Thread: Disable a BUTTON!

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    malaysia
    Posts
    57

    Disable a BUTTON!

    I have one page that will display all the data inside my database. at each data there will be an update link that can update the selected data!

    I want to make button that can be hide or shown depending the value of the textbox inside my update form!

    If the text box (txtBox1) contain no value,
    then display the button else, hide it!

    anyone can help me

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    use this function on the page_load event.

    VB Code:
    1. function set_state(){
    2. if txtbox1 == ""{
    3. button1.disabled = true
    4. }else{
    5. button1.disabled = false
    6. }
    7. }

  3. #3
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    if theres more than 1 button you'll need to put this in a loop as well

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    malaysia
    Posts
    57
    yes, i have 2 textbox, so how does the code look like if i want to add the AND function in the if statement?

    the logic is like this;
    if textbox1 and textbox2 is empty, disable button
    else display button!

    where should i put the code that you gave me?

    ---------------------------------------------------
    function set_state(){
    if txtbox1 == ""{
    button1.disabled = true
    }else{
    button1.disabled = false
    }
    }
    ----------------------------------------------

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    malaysia
    Posts
    57

    disable button if textbox contain value

    this is the code page that will contain two textbox (subject,section)
    and two button(update record,delete)--delete will empty the textbox value =''
    this is my update page(dbUpdate.asp)
    disable the two button if both the textbox contain value inside it!

    --------------------------------------------------------------------

    <tr>
    <td width="31%" height="28" align="center">
    <p align="right"><b><font face="Verdana" size="2">
    Subject :</font></b>
    </td>

    <td width="69%" height="28" align="center">
    <div align="left"><b><font face="Verdana" size="2">
    <input id="subject" name="subject" value="<%=(Recordset1.Fields.Item("subject").Value)%>" size="32" style="float: left"> </font></b></div>
    </td>
    </tr>

    <tr>
    <td width="39%" height="28" align="center">
    <p align="right"><b><font face="Verdana" size="2">
    Section :</font></b>
    </td>
    <td width="61%" height="28" align="center">
    <div align="left"><b><font face="Verdana" size="2">
    <input id="section" name="section" value="<%=(Recordset1.Fields.Item("section").Value)%>" size="32" style="float: left">
    </font></b></div>
    </td>
    </tr>

    <tr>
    <td width="100%" height="28" align="center" colspan="2">
    <b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> </font></b>
    </td>
    </tr>

    <tr>
    <td width="100%" height="28" align="center" colspan="2">
    <b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="submit" value="Update Record" name="submit">
    <!--JAVASCRIPT TEXTBOX CHANGER-->
    <input type="button" value="Delete Record" name="delete" a href="#" onClick="document.getElementById('subject').value =''; document.getElementById('section').value = '';">
    </font></b>
    <!--JAVASCRIPT TEXTBOX CHANGER END-->
    </td>
    </tr>


    When the textbox "Subject" and "Section" are empty, contain no value, then display the "Update Record" button!
    Else if the textbox "Subject" and "Section" contain a value/ data, then disable the "Update Record" and "Delete" button
    and display a "BACK" button to go back to previous page!
    can you show me step by step

    if posible, i want to know the <HEAD> script as well, please

  6. #6
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Originally posted by monie
    yes, i have 2 textbox, so how does the code look like if i want to add the AND function in the if statement?

    the logic is like this;
    if textbox1 and textbox2 is empty, disable button
    else display button!

    where should i put the code that you gave me?

    ---------------------------------------------------
    function set_state(){
    if txtbox1 == ""{
    button1.disabled = true
    }else{
    button1.disabled = false
    }
    }
    ----------------------------------------------
    Code:
    if (textone == "" && texttwo == "")
    {
    	button1.disabled = true;
    }
    else
    {
    	button1.disabled = false;
    }
    Please use the [code] tags when posting code/html it makes it much easier to read
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

Posting Permissions

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



Click Here to Expand Forum to Full Width