Tips on appending a search URL with "&*":

I need to create a search bar that connects to google.no (Norway). When searching for music, the URL should look like this: *. Can anyone help me understand how to add the (& *) at the end of a search?

.search {
  border: solid 1px grey;
  border-radius: 3px;
  padding: 10px;
  padding-left: 30px;
  padding-right: 30px;
  font-size: 15px;
  margin: 15px;
}
<form class="form" action="http://www.google.no/#q=">
  <input class="search" name="q" placeholder="Search...">
</form>

Answer №1

Submitting to this Google page is not possible due to the presence of an anchor # in the URL. This indicates that it does not follow the standard GET format that would typically be used when submitting a form to a URL. To overcome this, you will need to calculate the correct URL either using JavaScript or on the back-end.

If you opt for creating the correct URL using JavaScript, you can utilize the function encodeURIComponent(url) to properly escape the parameter.

Below is an example illustrating how this can be achieved:

var searchBox = document.querySelector('.search');
var form = document.querySelector('.form');

form.addEventListener('submit', function(event) {
  var value = searchBox.value;
  var escapedValue = window.encodeURIComponent(value);
  var url = "https://www.google.no/#q=" + escapedValue

  alert(url);
  window.location.href = url;

  event.preventDefault();
});
<form class="form" action="test">
  <input class="search" name="q" placeholder="Search...">
  <input type="submit" class="submit" value="Submit">
</form>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a Dropdown Selection Menu Dynamically with jQuery and SQL Query结果

I have a website that provides information from a database based on user-set parameters. Currently, the SQL Statement is loaded from a file to populate a dropdown menu with options. The HTML code used for this process is displayed below: while($rec = $con ...

The functionality of the jQuery click event is not functioning properly

I encountered a strange issue where the code below works perfectly fine when directly pasted into the browser (chrome console). However, it does not work when executed from my source file. <script type="text/javascript" > $(".test").click( ...

I'm having trouble with Material Design Slide Toggle as it lacks event.StopPropagation functionality. Any suggestions on what alternative I

When working with the Slide Toggle in Material Design, I noticed that it does not have a stopPropagation event. This is because the "MdSlideToggle.prototype._onChangeEvent" already includes a call to stopPropagation. So, what should be used instead? <m ...

What is the best way to ensure that deck.gl and react-map-gl are displaying properly on my screen?

Check out this code sandbox example that demonstrates my attempt to display a map within a specific component. However, I'm facing an issue where the deck.gl and react-map-gl elements are overflowing outside their parent container and extending to the ...

Position the personalized radio button to be in line with the first choice text

I frequently update this section with a new Jsfidle link to demonstrate the issue when the max-width is set to 300px. For responsive design, adding the "span" tag before radio buttons helps align input content with custom checkbox backgrounds. To see the ...

Switching the parameter to navigate to the appropriate page

Hi there, I'm looking to implement a quick change using the onchange parameter. Can someone assist me in using the onchange parameter to navigate to a new page? So, if someone selects for instance Basic info, they will be directed to a new page custo ...

How can I rename attribute values in a dropdown menu and ensure they work properly?

I'm facing an issue with my code. How can I store the option values in a database when they have numbering like value="1" or value="2"? Can I change it to something like value="1000" and have the other select box change to value="250" when selected? ...

How to place a Div element in the middle of a webpage

My webpage background features an image of old Tbilisi, and here is the code I am using: <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <style> #links { margin: 0 auto; ...

Ways to align one child to the end without affecting any other elements

I'm attempting to position only div3 at the flex-end of .app. If I use this code: .app { display: flex; flex-direction: column; height: 100vh; justify-content: flex-end; } Div3 goes where I want it, but everything else also moves dow ...

Place form at the center of the Bootstrap Modal

My question is, how can I center the entire form, including the input fields and labels, within the modal? Here is also a helpful Fiddle: http://example.com, although the snippet provided should work as well. <script src="https://example.com/bootstr ...

How can I adjust a centered container div to fit properly on a mobile device

Exploring the centering of a particular div: #container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); height: 550px; width: auto; background: rgba(28, 28, 54, 0.70); padding: 15px; border: 1px solid #1c ...

Struggling to get CORS request to function properly

I am encountering a CORS issue while trying to retrieve data from a webservice on a different domain. Within my controller, I have the following code: $http({method: 'GET', url : 'http://somewebserviceapi.com?idAppli=' + appId, header ...

Bootstrap grid. Instead of moving to the next row, scroll horizontally when the content overflows

Here is the code snippet: <div class="row shochatgroup"> <div *ngFor="let message of messages" class="col-auto"> <button *ngIf="message.state.attributes.shochatpaid > 0 && message.state.at ...

How can you fix a navbar that won't stay in place?

I'm facing an issue with this example: When I scroll, the navbar moves along due to the fixed property, which affects the overall look. How can I make it disappear when scrolling, while keeping the logo intact? Can someone suggest if this layout is ...

Angular HTML fails to update correctly after changes in input data occur

Within my angular application, there is an asset creator component designed for creating, displaying, and editing THREE.js 3D models. The goal was to implement a tree-view list to showcase the nested groups of meshes that constitute the selected model, alo ...

Utilizing React Bootstrap with TypeScript for Styling Active NavItem with Inline CSS

Is it possible to change the background color of the active NavItem element to green using inline CSS in React Bootstrap and React Router Dom? I am currently using TypeScript 2.2 and React. If not, should I create a CSS class instead? Here is the code sni ...

Troubleshooting regex validation issues in a JSFiddle form

Link to JSFiddle I encountered an issue with JSFiddle and I am having trouble figuring out the root cause. My aim is to validate an input using a regex pattern for a person's name. $("document").ready(function() { function validateForm() { var ...

Setting a default value within an input tag: A step-by-step guide

const [userData, setUserData] = useState([]); const handleUserInfo = (id) => { fetch(`https://602e7c2c4410730017c50b9d.mockapi.io/users/${id}`) .then(res => res.json()) .then(data => setUserData(data)) } <inpu ...

What is the best way to spin a div HTML layer?

I'm trying to modify a Div layer that looks like this: ... <style type="text/css"> <!-- #newImg { position:absolute; left:180px; top:99px; width:704px; height:387px; z-index:1; background-image:url(../Pictures/rep ...

IE10 is not effectively handling multiple media queries

Within my CSS file, I've included a series of media queries specifically tailored for ie10... @media screen and (max-width :1510px), screen\0{ div.jw-menu-3col-sm li a .menuItem { padding: 0 12px; } } @media screen ...