1

I am trying to set the value of HTML file using a javascript of another HTML file.

for example :

html1.html 
js1.js // this is for html1.html

html2.html // inside this html file, I wanted to set the value and innerHTML of 1 element using js1.js

for example element:

 <input id="cID" name="cID" type="text" class="required form-control">

IS there anyway to achieve it??

Thank you and Regards,

4
  • How will you take the html form one page to another using JS ? generally we pass only values from one page to another using querystring or session etc ! What are you trying to achieve ! Commented Aug 9, 2019 at 6:56
  • @VinodkumarG , on the comment beside html2.html sir, I want to achieve on how to set the value of element inside html2.html using the javascript of html1.html Commented Aug 9, 2019 at 6:59
  • you can't do that. you can only load html2.html into thml1.html and change it there. but it won't be saved. Commented Aug 9, 2019 at 7:13
  • You can set value in localStorage or globally and then use it. But for that also you need a separate js file for html2 Commented Aug 9, 2019 at 7:42

1 Answer 1

2

That's at least really impractical.

HTML pages "aren't made"(well, it's what I want any new dev to think anyway) to communicate with each others. Sure, you can make it happen by either using iframe/popup/localStorage/cookies. But it usually is a bad solution to any problem you're having, with another simpler/better/stronger solution waiting for you to find it.

In details :

Usually better solutions to problems generating this kind of question :

  1. include js1.js in html2, nothing prevent you from including one JS multiple time (best solution, IF it's sufficient to solve the issue)

  2. use a server-side solution like template, session, include, ajax... (nearly always the best solution if posssible)

  3. just use one html, and change its content in JS (nearly always the best solution if solution 2 isn't possible)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you sir.. I'll try to make it work with localstorage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.