2

I want the following URL to be manipulated and opened in a new tab once I pass the value of email ID and click submit. The searchText in myUrl is the param for email ID:

HTML:

<textarea name="email" id="email" cols="30" rows="10"></textarea>
<button id="myButton">submit</button>

JavaScript:

const myUrl = new URL('[email protected]&site=something&mobileVersion=&locale=&forceAaaApplication=');

1 Answer 1

2

you can use this:

HTML:

<button id="myButton" onclick="sbButtonClick()">submit</button>

JavaScript:

const textarea = document.getElementById("email");
let myUrl = null;

function sbButtonClick() {
    myUrl = new URL(`something.com?searchText=${textarea.value}&site=something&mobileVersion=&locale=&forceAaaApplication=`);

    // do something with myUrl
}

Edit

to get multiple email addresses one of the easiest ways is this way:

const textarea = document.getElementById("email");

function sbButtonClick() {
    // split the text by line breaks so each address should be in a separate line
    const emailArray = textarea.value.split("\n");

    // here you open tab for each email address
    for (let address of emailArray) {
        window.open(`something.com?searchText=${address}&site=something&mobileVersion=&locale=&forceAaaApplication=`);
    }
}

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

2 Comments

Thank you, this was really helpful :) Can you also show me how I can input multiple emails at once and on submit it will open multiple tabs?
here I edited the post for what you asked. please let me know if you need further information :)

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.