• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 JavaScript, TS 게시판 자바스크립트 form select값 저장하는 법

자바스크립트 form select값 저장하는 법

5 글 보임 - 1 에서 5 까지 (총 5 중에서)
  • 글쓴이
  • #72925

    이형민
    참가자
    악기
    <select class="instrument form-select" aria-label="Default select example">
    <option selected>선택하기</option>
    <option value="select" selected>선택하기</option>
    <option value="piano">피아노</option>
    <option value="acoustic-guitar">어쿠스틱 기타</option>
    <option value="drum">드럼</option>
    <option value="electronic-guitar">일렉기타</option>
    <option value="synthesizer">신디사이저</option>
    <option value="string-instrument">현악기</option>
    <option value="wind-instrument">관악기</option>
    <option value="gugak instrument">국악기</option>
    </select>
    
    이러한 코드에서 셀렉터에서 선택된 값을 파이어스토어에 저장하려고
    instrument0: document.getElementById("#instrument").val(),
    
    이렇게 코드를 짰습니다. 저장이 안되는데 어떻게 코드를 짜야하나요?
    #72935

    codingapple
    키 마스터
    val()말고 .value 합시다
    #73043

    이형민
    참가자
    $('#send').click(function () {
    alert('잠시만 기다려주세요.')
    var file1 = document.querySelector('#image').files[0];
    var storageRef = storage.ref();
    var 저장경로 = storageRef.child('image/' + file1.name + 내uid);
    var 업로드 = 저장경로.put(file1)
    var file2 = document.querySelector('#bgm').files[0];
    var storageRef = storage.ref();
    var 저장할경로 = storageRef.child('bgm/' + file2.name + 내uid);
    var 업로드작업 = 저장할경로.put(file2)
    업로드작업.on('state_changed',
    // 변화시 동작하는 함수 
    null,
    //에러시 동작하는 함수
     (error) => {
    console.error('실패사유는', error);
     },
    // 성공시 동작하는 함수
     () => {
    업로드.snapshot.ref.getDownloadURL().then((url1) => {
    console.log('이미지 업로드 경로', url1);
    업로드작업.snapshot.ref.getDownloadURL().then((url2) => {
    console.log('Bgm 업로드 경로', url2);
    var 저장할거 = {
    title0: $('#title').val(),
    content0: $('#content').val(),
    mood0: document.getElementById("#mood").value,
    genre0: document.getElementById("#genre").value,
    instrument0: document.getElementById("#instrument").value,
    theme0: document.getElementById("t#heme").value,
    tempo0: document.getElementById("#tempo").value,
    vocal0: document.getElementById("#vocal").value,
    price0: parseInt($('#price').val()),
    date0: new Date(),
    image0: url1,
    bgm: url2,
    uid: JSON.parse(localStorage.getItem('user')).uid,
    name0: JSON.parse(localStorage.getItem('user')).displayName
     }
    db.collection('product').add(저장할거).then((result) => {
    console.log(result);
    alert('업로드가 완료되었습니다.');
    window.location.href = "market.html";
     }).catch((err) => {
    console.log(err)
     })
     });
     });
     }
     );
    
    
     })
    이렇게 코드를 작성했는데, 업로드 버튼을 눌러보면 
    upload.html:296 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'value')
    
    이런 오류를 띄웁니다
        at upload.html:296:72
    #73044

    이형민
    참가자
    upload.html:296 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'value')
        at upload.html:296:72
    #73085

    codingapple
    키 마스터
    72번줄에 뭐가 이상하다는소리같은데 "t#heme" 이런거 오타인가봅니다
5 글 보임 - 1 에서 5 까지 (총 5 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠