top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to change the value of a DIV using JavaScript?

0 votes
897 views
How to change the value of a DIV using JavaScript?
posted Feb 24, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

If you are using jquery just use

$(document).ready(function(){
 $("your div id").text("your text");
});

Also don't forget to use the jquery library in your code as

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
answer Feb 29, 2016 by Aman Mehrotra
0 votes

We use this very frequently

document.getElementById("<Your DIV ID>").innerHTML=<value of inner HTML>;

So in short you may need to use one of the following -

document.getElementById(id).innerHTML = new HTML
document.getElementById(id).attribute=new value
answer Feb 24, 2016 by Salil Agrawal
Similar Questions
0 votes

Write validation functions and modify the onSubmit event Handler in the form code to validate the following form fields:

  1. Phone Number
    • Must be entered
    • Must be below format
    XXX-XXX-XXXX
    XXX.XXX.XXXX
    XXX XXX XXXX
+3 votes

My form is somewhat like this:-

 <form id="form1" method="post" name="form1">
 //...fields like firstname, email......
 <button type="submit" id="submit" name="submit" onclick="validate(this)">SUBMIT</button>
 < /form>

The javascript validate function:-

function validate(ref)
{
    if(document.form1.firstname.value=="")
    {
            window.alert("First Name Cannot be Blank");
            return;
    }

    // validating other fields like email... If any field is invalid return 
    document.form1.action="response"
    document.form1.submit()
} 

Now what the problem is suppose I left the firstname field blank and click submit button then windows alerts that firstname field is mandatory....and as soon as I click the OK button in alert form the form is posted...

Now question is that I assign the action attribute after validating all the fields and if any one is invalid the function returns in which case action attribute of the form is not assigned then how the form is submitted.
The form should have been submitted after all the validation tests will have been successful and controls would have reached document.form1.submit(). And what is the solution for this.

I am using Python Flask and rendering template using jinja2.

+1 vote

I want the javascript API which could capture the screen of the client. Does anyone knows about it?

...