Home > Software design >  Javascript password button open URL in targeted element
Javascript password button open URL in targeted element

Time:04-12

I learned how to open a link using a password and button. I used the following code:

<input type="text" id="text" />
<input type="button" id="btn" value="Submit" onClick="window.location=url;" />

<script>
$("#btn").click(function() {
window.location="example.com/" $("#text").val();})
</script>

What I would like to figure out is whether I can target a div element for the link to open within.

I've been using the following script to load html pages into a specified div element with a link:

<div  id="pageone"></div>
<a href="" onclick="loadSAMEDiv1(); return false;">link</a>

<script>
function loadSAMEDiv1() { 
$.ajax({ 
 url: 'item1.html', 
 success: function(data) { 
      $('#pageone').html(data); 
 } 
 }); 
} 
</script>

I guess I'm wondering if there's a way to make the password url made by the first script open in a targeted div, like it does in the second script. So when you click the button element it will make the url using the password entered into the text box and load it into a div like #pageone.

CodePudding user response:

The simplest way to do this is with Ajax load(). Try this.

<input type="text" id="text" />
<input type="button" id="btn" value="Submit"/>

<div  id="pageone"></div>

<script>
    $("#btn").on("click", function() {
        $("#pageone").load("example.com/" $("#text").val());
    });
</script>
  • Related